package info.gridworld.actor;

import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.util.ArrayList;

public class QuickCrab extends CrabCritter {

	@Override
	public ArrayList<Location> getMoveLocations() {
        ArrayList<Location> locs = new ArrayList<Location>();
        
        Location loc1 = getLocation().getAdjacentLocation(getDirection() + Location.LEFT);
        Location loc2 = getLocation().getAdjacentLocation(getDirection() + Location.RIGHT);
        
        if(isEmptyInOneLocation(loc1)) {
        	Location leftLoc = loc1.getAdjacentLocation(getDirection() + Location.LEFT);
        	if(isEmptyInOneLocation(leftLoc)) {
        		locs.add(leftLoc);
        	}
        }
        if(isEmptyInOneLocation(loc2)) {
        	Location rightLoc = loc2.getAdjacentLocation(getDirection() + Location.RIGHT);
        	if(isEmptyInOneLocation(rightLoc)) {
        		locs.add(rightLoc);
        	}
        }
        if(!locs.isEmpty()) {
        	return locs;
        }
        
        if(isEmptyInOneLocation(loc1)) {
        	locs.add(loc1);
        }
        if(isEmptyInOneLocation(loc2)) {
        	locs.add(loc2);
        }
        
        return locs;
	}
	
	private boolean isEmptyInOneLocation(Location loc) {
		return getGrid().isValid(loc) && getGrid().get(loc) == null;
	}

//	@Override
//	public ArrayList<Location> getLocationsInDirections(int[] directions) {
//        ArrayList<Location> locs = new ArrayList<Location>();
//        Grid gr = getGrid();
//        Location loc = getLocation();
//    
//        for (int d : directions)
//        {
//            Location neighborLoc = loc.getAdjacentLocation(getDirection() + d);
//            Location nextTwoLoc = neighborLoc.getAdjacentLocation(getDirection() + d); 
//            if (gr.isValid(nextTwoLoc))
//                locs.add(nextTwoLoc);
//        }
//        return locs;
//	}
	
	
	
	
}
